<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
    <van-button @click="logout()">退出</van-button>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'
import axios from "axios";

export default {
  name: 'HomeView',
  data(){
    return{

    }
  },
  components: {
    HelloWorld
  },methods:{
    logout(){
      console.log(this.$store.state.token)
      axios({
        url:"/user/logout.do",
        method:"get",
        headers:{
          "ddstoken":this.$store.state.token
        }
      }).then(res=>{
        if (res.data.code === 200){
          this.$toast("退出成功")
          this.$store.commit("setToken",0)
          this.$router.push("/login")

        }else{
          this.$toast("退出失败")
        }
      })
    }
  }
}
</script>
